<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\BannerModel;
use app\common\model\Feedback;
use app\common\model\MenuModel;
use app\common\model\OperationModel;
use fast\Tree;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $jump_type = $this->request->request('jump_type','mini');

        // 轮播图
        $banner = BannerModel::getList($jump_type);
        // 菜单栏
        $menu = MenuModel::getList($jump_type);
        // 运营区
        $operation = OperationModel::getList($jump_type);

        $data = [
            'banner' => $banner['data'],
            'menu' => $menu['data'],
            'operation' => $operation['data'],
        ];

        $this->errorReturn(200, $data, '请求成功');
    }

    /**
     * 配置信息
     *
     */
    public function config()
    {
        $system = model('app\common\model\SystemModel')->get(1);
        $data = [
            'name'                      => $system->title,
            'logo'                      => full_url($system->logo),
            'about'                     => $system->about,// 关于我们
            'privacy_agreement'         => $system->privacy_agreement,//隐私协议
            'registration_agreement'    => $system->registration_agreement,//注册协议
            'pay_agreement'             => $system->pay_agreement,//支付协议
            'beian'                     => $system->beian,//备案号
            'index_view'                => $system->index_view,//首页展示
            'withdraw_limit'            => $system->withdraw_limit,//提现-最低提现额度
            'withdraw_service_charge'   => $system->withdraw_service_charge,//提现-手续费(百分比)
            'is_user_score_award'       => $system->is_user_score_award,//开启用户积分奖励:0=否,1=是
            'address'                   => $system->address,//地址
            'lat'                       => $system->lat,//经纬度
            'lng'                       => $system->lng,//经纬度
            'video'                     => full_url($system->video),//视频
            'video_image'               => full_url($system->video_image),//视频封面
        ];
        $this->success('请求成功',$data);
    }


    /**
     * 意见反馈
     *
     * @param string $content
     */
    public function feedback(Feedback $Feedback, \app\api\validate\UserValidate $UserValidate)
    {
        $params = $this->request->post();
        if(!$UserValidate->check($params,[],'feedback')){
            $this->errorReturn(40001,$params,$UserValidate->getError());
        }
        $params['user_id'] = $this->auth->id;
        $return = $Feedback->addLog($params);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }
}
